package com.PlantVsZombies.Plants;

import java.awt.Graphics;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Iterator;

import com.PlantVsZombies.common.Plant;
import com.PlantVsZombies.constant.PlantType;
import com.PlantVsZombies.ui.PlantsMap;
import com.PlantVsZombies.util.ImageUtil;

/**
 * 太阳花
 * 
 * @author Administrator
 *
 */
public class SunFlower extends Plant implements Runnable, Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	int speed = 0;
	int Index = 0;
	// 构造
	public SunFlower(int x, int y) {
		this.x = x;
		this.y = y;
		this.plantImage = ImageUtil.SUNFLOWER;
		this.life = 30;
	}

	public int getX() {
		return x;
	}

	public void setX(int x) {
		this.x = x;
	}

	public int getY() {
		return y;
	}

	public void setY(int y) {
		this.y = y;
	}
	//生产阳光
	public Sun producelight() {
		Sun su = new Sun(x, y);
		su.start();
		PlantsMap.getSun().add(su);
		return su;
	}
	public void drawMe(Graphics g, int x2, int y2) {
		g.drawImage(plantImage.getImage(), x2, y2, null);

	}
	@Override
	public void shootBullet() {

	}

	@Override
	public PlantType getType() {
		// TODO Auto-generated method stub
		return PlantType.SunFlower;
	}

	@Override
	public int doRun() {
		if(isAttacked && life>0){
			life--;
		}
		if(life == 0){
			this.setLive(false);
			this.isAttacked = false;
			return 0;
		}
		try {
			Thread.sleep(200);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		if (++speed % 30 == 0 && this.isLive()) {
			producelight();
		}
		return 1;
	}

}
